package filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 顾客登录过滤器
 * 作者：孩子他爹
 */
@WebFilter(filterName = "FilterCusLogin",urlPatterns = {"/BeforePage/Customer/goodsQueryOne.jsp","/BeforePage/Customer/index.jsp","/BeforePage/Customer/ordAddress.jsp",
        "/BeforePage/Customer/ordQuery.jsp","/BeforePage/Customer/Page.jsp","/BeforePage/Customer/shopQuery.jsp","/BeforePage/Customer/shopUpdate.jsp",
"/BeforePage/GUIMEI/*"})
public class FilterCusLogin implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest request= (HttpServletRequest) req;
        HttpServletResponse response= (HttpServletResponse) resp;
        Object objCus=request.getSession().getAttribute("customer");
        if(objCus==null){
            response.sendRedirect("../../Cuslogin.jsp");
        }else {
            chain.doFilter(req, resp);
        }
    }

    public void init(FilterConfig config) throws ServletException {

    }

}
